import { AxiosRequestConfig,AxiosPromise } from "axios";
import request from "./request";

function apiHandle<T, K>(requestConfig: {
  url: string
  method: 'GET' | 'POST' | 'PUT' | 'DELETE'
}): (data?: T, options?: AxiosRequestConfig) => AxiosPromise<K> {
  const { url, method } = requestConfig;
  const res = (data?: T, options?: AxiosRequestConfig): AxiosPromise<K> => {
    return request({
        url,
        method,
        data,
        ...options
    })
  }
  return res
}

export default apiHandle